<template>
	<view>
		<image src="http://imcdn.shimaruanchuang.cn/chat/1708169211150bHL87NNQG1x4ea8abda383092fd2087a08dbea0aec4d.jpg"
			style=" height: 250rpx; margin-top: 30%;width: 70%; margin-left: 15%;"></image>
		<view style="margin-top: 10%;width: 70%; margin-left: 15%;">
			<u--input color="#acacac" placeholder="手机号码:" border="surround" v-model="tel" shape="circle"
				value="admin"></u--input>

		</view>

		<view style="margin-top: 5%;width: 70%; margin-left: 15%; ">
			<u--input color="#acacac" placeholder="输入密码:" border="surround" v-model="passWord" shape="circle"
				value="111111"></u--input>
		</view>
		<view style="margin-top: 5%;width: 70%; margin-left: 15%; ">
			<u--input color="#acacac" placeholder="输入昵称:" border="surround" v-model="nickName" shape="circle"
				value="111111"></u--input>
		</view>


		<view style=" margin-left: 35%; "> 
			<view style="margin-top: 15%; margin-left: 9%;   justify-content: center; width: 200rpx;">
				<button  size="mini" type="primary" hover-class="is-hover" @click="registerFun">注册</button>
			</view>
		</view>


	</view>
</template>

<script>
	import {
		register,
	} from "../../config/api.js"
	export default {
		data() {
			return {
				value: '',
				tel: null,
				passWord: null,
				nickName: null,
			}
		},
		methods: {
			registerFun() {
				// 往后端传的参数
				let param = {
					tel: this.tel,
					passWord: this.passWord,
					nickName: this.nickName,
				}
				if (param.tel == null || param.tel == "" || param.tel.length != 11) {
					uni.showToast({
						title: '手机号输入有误',
						icon: "error"
					})
					return;
				}
				if (param.passWord == null || param.passWord == "") {
					uni.showToast({
						title: '密码不能为空',
						icon: "error"
					})
					return;
				}
				if (param.passWord.length < 6) {
					uni.showToast({
						title: '密码不能小于6位',
						icon: "error"
					})
					return;
				}
				if (param.nickName == null || param.nickName == "") {
					uni.showToast({
						title: '昵称不能为空',
						icon: "error"
					})
					return;
				}

				// 发出post，假设需要带上token auth=true  代表该请求会默认带上登录的token
				register(param, {
					custom: {
						auth: false
					}
				}, ).then((e) => {
					if (e.code == 200) {
						uni.showToast({
							title: '注册成功',
							icon: "success"
						})
						uni.navigateTo({
							url: "/pages/login/login"
						})
					}

				}).catch(() => {
					console.log("请求失败了")
				})
			}
		}
	}
</script>

<style>
	page {
		background: #1a1a1a;
	}
</style>